package com.pi.pro.xcmg.am.was.edi.mes.service;


import com.pi.common.utils.TextUtils;
import com.pi.core.exchange.vo.NamedServiceProxy;
import com.pi.pro.xcmg.am.common.vo.edi.KitDocumentQueryData;
import com.pi.pro.xcmg.am.common.vo.edi.KitDocumentReplyData;
import com.pi.pro.xcmg.am.was.edi.mes.common.MesWasExchangeSupport;
import com.pi.wms.fac.conn.HttpAccessUrl;
import com.pi.wms.fac.conn.HttpConstants;
import com.pi.wms.fac.conn.HttpclientProxy;
import lombok.Getter;
import lombok.Setter;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;


/**
 */

@Getter
@Setter
public class KitDocumentServiceProxy implements NamedServiceProxy {

    private String category;
    private String code;

    private HttpclientProxy mesDocumentClient;
    private HttpAccessUrl mesDocumentQueryPostAccessUrl;

    //
    public KitDocumentReplyData query(KitDocumentQueryData params) {
        KitDocumentReplyData replyData=null;
        String replyText = "";
        if (this.mesDocumentClient==null){
            return MesWasExchangeSupport.error("install client error");
        }
        Map<String,String> headers = new HashMap<>();
        try{
            replyText = this.mesDocumentClient.post(this.mesDocumentQueryPostAccessUrl, null, headers,
                    HttpConstants.URL_METHOD_POST, TextUtils.toJsonText(params));
            replyData= TextUtils.toObject(replyText, KitDocumentReplyData.class);
        }catch (Exception e){
            e.printStackTrace();
            replyText="query kit document error.//"+e.getMessage();
            replyData= MesWasExchangeSupport.error(replyText);
        }
        return replyData;
    }


}
